

cap log using "Loanshark_OnlineAppendix_Tables.smcl", replace

*******************************
*
* Produce Online Appendix Tables and Event Study Figures
*
*******************************





*****************************************************************************************************************
****************************** Appendix Table 1: The Effect of Borrow History on Loan Terms *********************
*****************************************************************************************************************

use loanshark_data_final, clear

** Setup - Generate new vars
gen noborrowhist = (borrowhist==0 & borrowhist!=.)
label var noborrowhist "Never borrowed from this lender before"
label var borrowhist "Times previously borrowed from this lender"

xtset shark5_bor
qui xi: xtreg lloan noborrowhist borrowhist i.year ,fe
est store r1
qui xi: xtreg lloan noborrowhist borrowhist i.year conditn* reasonn* ,fe
est store r2
qui xi: xtreg rate_pct noborrowhist borrowhist i.year ,fe
est store r3
qui xi: xtreg rate_pct noborrowhist borrowhist i.year conditn* reasonn* ,fe
est store r4
esttab r1 r2 r3 r4,keep(noborrowhist borrowhist) se

******************************************************************************************************************
****************************** Appendix Table 2. The Effect of Repayment History on Loan Terms *******************
******************************************************************************************************************

eststo clear


local vars "repayendD repaytime default"
foreach v in `vars'{
	
	 bys shark5_bor (year month loanno): gen `v'L1=`v'[_n - 1]
}


* Loan (borr-lender FE)
lab var repaytimeL1 "Lag 1: Time to repay (months)"
lab var defaultL1 "Lag 1: Default"
lab var repayendDL1 "Lag 1: Repaid Eventually"
qui xi: areg  lloan repaytimeL1 i.year ,abs(shark5_bor)
est store f1
qui xi: areg  lloan defaultL1 i.year   ,abs(shark5_bor)
est store f2
qui xi: areg  lloan repayendDL1 i.year  ,abs(shark5_bor)
est store f3



* Rate (borr-lender FE)
sum rate_pct 
qui xi: areg  rate_pct repaytimeL1 i.year ,abs(shark5_bor)
est store f4
qui xi: areg  rate_pct defaultL1 i.year ,abs(shark5_bor)
est store f5
qui xi: areg  rate_pct repayendDL1 i.year,abs(shark5_bor)
est store f6

esttab f1 f2 f3 f4 f5 f6, drop(_Iyear*) se

log close

	
	


*************************************************************************************
****************************** Figure 2: Event Studies ************************
*************************************************************************************

cd "$graphroot"

forval s = 1/4{
	
foreach v in rate_pct loan loanasked lendrate totalpaid latefee_share default howrepayn3 howrepayn2 lenderrequestwork conscription noforce remind repayend {
	
	local rate_pctlbl "Nominal Rate"	
	local loanlbl "Loan"
	local loanaskedlbl "Loan Asked"
	local lendratelbl "Percent of Loan Asked Lent"
	local totalpaidlbl "Total Paid"
	local defaultlbl "Default"
	local howrepayn2lbl "Repay by Borrow from Friends"
	local howrepayn3lbl "Repay by Borrow from Family"
	local repayendlbl "Repaid Eventually"
	local latefee_sharelbl "Late Fee Paid as a Share of Loan"
	local conscriptionlbl "Request Accepted if Requested"
	local noforcelbl "No Harassment"
	local remindlbl "Reminder Call"
	local lenderrequestworklbl "Lender Requested Work for Him"

	* baseline
	tempfile `v'_coef_1
	qui xi: reg `v' i.year 
	qui test  _Iyear_2010= _Iyear_2011= _Iyear_2012=_Iyear_2013=0
	local `v'_pval_1: disp %-9.3f r(p)
	parmest, saving(``v'_coef'_1, replace)

	* FE (borrower)
	tempfile `v'_coef_2
	qui xi: areg `v' i.year, abs(id)
	qui test  _Iyear_2010= _Iyear_2011= _Iyear_2012=_Iyear_2013=0
	local `v'_pval_2: disp %-9.3f r(p)
	parmest, saving(``v'_coef'_2, replace)

	* FE (lender)
	tempfile `v'_coef_3
	qui xi: areg `v' i.year, abs(sharkid5) 
	qui test  _Iyear_2010= _Iyear_2011= _Iyear_2012=_Iyear_2013=0
	local `v'_pval_3: disp %-9.3f r(p)
	parmest, saving(``v'_coef'_3, replace)

	* FE (borr-lender)
	tempfile `v'_coef_4
	qui xi: areg `v' i.year, abs(shark5_bor)
	qui test  _Iyear_2010= _Iyear_2011= _Iyear_2012=_Iyear_2013=0
	local `v'_pval_4: disp %-9.3f r(p)
	parmest, saving(``v'_coef'_4, replace)

	preserve

			use ``v'_coef'_`s', clear
			replace parm = "_Iyear_2009" if parm == "_cons"
			replace parm = substr(parm,8,11)
			destring parm,replace
			rename parm year
			replace estimate = 0 if year ==2009	    
			replace min95 = 0 if year ==2009
			replace max95 = 0 if year ==2009
			rename estimate `v'_est_`s'
			rename max95 `v'_max95_`s'
			rename min95 `v'_min95_`s'
			keep year `v'*
			sort year
			
			# delimit;
			twoway (line `v'_est_`s' year, lw(medthick) color(orange))
				   (scatter `v'_est_`s' year, ms(Oh) color(orange))
				   (rarea `v'_max95_`s' `v'_min95_`s' year, fcolor(ltblue%50) lcolor(navy) lpattern(dash)),
				xlabel(2009(1)2016, gmin gmax ticks labsize(vsmall)) xscale(range(2009 2016))
			  title("``v'lbl'",size(small))  xtitle("") 
			  ylabel(, angle(horizontal) labsize(vsmall))
			  xline(2013 ,lc(red) lw(thin))  
			  yline(0, lc(gray) lp(dash)) 
			  plotregion(lw(none)) 
			  note("P-val for Parallel Trend Testing before Enforcement = ``v'_pval_`s'''", size(vsmall))
			  scheme(s1color) legend(off)  
			  saving(event_`v'_`s', replace) ;
			# delimit cr
		
	restore
	}
	
local spec1lbl "OLS"
local spec2lbl "Borrower fixed effects"
local spec3lbl "Lender fixed effects"
local spec4lbl "Borrower-lender fixed effects"

graph combine   "$graphroot/event_rate_pct_`s'.gph" "$graphroot/event_loan_`s'.gph" ///
				"$graphroot/event_loanasked_`s'.gph" "$graphroot/event_lendrate_`s'.gph" ///
				"$graphroot/event_totalpaid_`s'.gph"  "$graphroot/event_latefee_share_`s'.gph"  ///
				"$graphroot/event_default_`s'.gph"  "$graphroot/event_howrepayn3_`s'.gph" ///
				"$graphroot/event_howrepayn2_`s'.gph" "$graphroot/event_lenderrequestwork_`s'.gph" ///
				"$graphroot/event_conscription_`s'.gph" "$graphroot/event_noforce_`s'.gph" ///   		
				"$graphroot/event_remind_`s'.gph" "$graphroot/event_repayend_`s'.gph"  ///			    
  , l1title("Estimated coefficients of Year Dummies", size(small)) xcommon ///
    scheme(s1color) b1title("Year", size(small)) imargin(small) col(2) ///
    note("Note: Footnotes below panel D.", size(vsmall)) 
graph export "$root/New_version/event_nocontrol_spec`s'.png", replace	
	
}

 
graph combine   "$graphroot/event_rate_pct_4.gph" "$graphroot/event_loan_4.gph" ///
				"$graphroot/event_loanasked_4.gph" "$graphroot/event_lendrate_4.gph" ///
				"$graphroot/event_totalpaid_4.gph"  "$graphroot/event_latefee_share_4.gph"  ///
				"$graphroot/event_default_4.gph"  "$graphroot/event_howrepayn3_4.gph" ///
				"$graphroot/event_howrepayn2_4.gph" "$graphroot/event_lenderrequestwork_4.gph" ///
				"$graphroot/event_conscription_4.gph" "$graphroot/event_noforce_4.gph" ///   		
				"$graphroot/event_remind_4.gph" "$graphroot/event_repayend_4.gph"  ///			    
  , l1title("Estimated coefficients of Year Dummies", size(small)) xcommon ///
    scheme(s1color) b1title("Year", size(small)) imargin(small) col(2) ///
    note("Notes: All estimates control for year dummies." "1. Repay by borrowing from family include both immediate family and relatives." "2. Default refers to whether the borrower repaid in full and on time." "3. Lender requested work for him refers the the situation where lenders asked lenders to work for  him in the event of default.", size(vsmall))
graph export "$root/New_version/event_nocontrol_spec4.png", replace











